package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwFarmRoominfoService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by BKWJA on 2019/1/6.
 * 农家乐——农家住宿信息 控制类
 */
@Slf4j
@CrossOrigin(allowCredentials = "true")
@RequestMapping("farmroom")
@Controller
public class XwFarmRoominfoController extends IMoocExceptionHandler {

    @Autowired
    private XwFarmRoominfoService xwFarmRoominfoService;


    /**
     * 获取农家乐店铺 住宿信息
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @RequestMapping("/getfarmroomlist")
    @ResponseBody
    public JSONObject getfarmroomlist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                      @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "sortfild",defaultValue = "farm_room_createtime")
                                                  String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                      @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                      @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                      String farm_encryptId,HttpServletRequest request){
        return xwFarmRoominfoService.getfarmroomlist(pageindex,pagesize,starttime,endtime,sortfild,sortway,
                searchval,searchkey,farm_encryptId,request);

    }

    /**
     *  新建 修改农家乐住宿信息
     * @param room_id 住宿id
     * @param roomType 住宿类型
     * @param remarks 住宿说明
     * @param roomprice 住宿价格
     * @param roomnum 住宿晚数
     * @param farm_encryptId 农家乐加密id
     * @param business_encryptId 店铺加密id
     * @param request
     * @return
     */
    @RequestMapping("/updatefarmroom")
    @ResponseBody
    public JSONObject updatefarmroom(Integer room_id,String roomType,String remarks,String roomprice,String roomnum,
                                     String farm_encryptId,String business_encryptId,HttpServletRequest request){
        return xwFarmRoominfoService.updatefarmroom(room_id,roomType,remarks,roomprice,roomnum,
                farm_encryptId,business_encryptId,request);
    }

    /**
     * 根据住宿id，删除对应的信息
     * @param room_id 住宿id
     * @param request
     * @return
     */
    @RequestMapping("/delfarmroom")
    @ResponseBody
    public JSONObject delfarmroom(String room_id,HttpServletRequest request){
        return xwFarmRoominfoService.delfarmroom(room_id,request);
    }

}
